package com.pwc.deadletter;

import com.pwc.utils.RabbitUtil;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author fantuancyh
 * @data 2021/8/21
 */
public class DeadLetterConsumer {
    private static final String DEAD_QUEUE = "dead-queue";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitUtil.makeChannel();
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println(new String(message.getBody(), "utf-8"));
            channel.basicAck(message.getEnvelope().getDeliveryTag(), false);
        };
        CancelCallback cancelCallback = (consumerTag) -> {
            System.out.println("error");
        };
        boolean autoAck = false;
        channel.basicConsume(DEAD_QUEUE, autoAck, deliverCallback, cancelCallback);
    }
}
